<?php
class System_App_Noyau{
    public static $systemClass = array();
    public static $systemConfig = null;
    
    public $resultAction;
    public $returnDispatch;
    
    private function _getConfig(){
        if( self::$systemConfig === null ){
            $src = APP_PATH.'config/config.ini';
            if( file_exists($src) ){
                self::$systemConfig = parse_ini_file($src, true);
            }
        }
        return self::$systemConfig;
    }
    
    public function register( $className ){
        self::$systemClass[$className] = $this;
    }
    
    public function preDispatch(){
        
    }
    
    public function dispatch(){
        
    }
    
    public function postDispatch(){
        
    }
    
    public function __get( $key ){
        $val = false;
        if(property_exists(get_class(), $key ) ){
            $val = $this->$key;
        }elseif( isset( self::$systemClass[$key] ) ){
            $val = self::$systemClass[$key];
        }
        
        return $val;
    }
    public function __set( $key, $val ){
        if(property_exists(get_class(), $key ) ){
            $this->$key = $val;
        }else{
            self::$systemClass[$key] = $val;
        }
    }
    
    public function getConfig($rubrique = ''){
        $aConfig = $this->_getConfig();
        if( $rubrique !== '' && isset( $aConfig[$rubrique] ) ) return $aConfig[$rubrique];
        else return $aConfig;
    }
    
    public function trace($var){
        if(is_array($var) || is_object($var) ){
            echo '<pre>';
            print_r( $var );
            echo '<pre>';
        }else{
            echo $var;
        }
        exit;
    }
}
?>
